# -*- coding: utf-8 -*-            
# @Time : 2025/7/2 17:00
# @FileName: utils.py
# @Target:
import json, codecs, time, os
import requests
from django.conf import settings

with codecs.open(
        filename='idmi_backend/data_configs/cuzu_labels_20250627.json',
        mode='r', encoding='utf-8'
) as fr:
    '''
    Customer Satisfaction 相关的标签体系
    '''
    CUZU_LABELS = json.load(fp=fr)




class CuZuLabel2IntValue:
    def __init__(self):
        self._cuzu_labels_1_grade = {}
        self._cuzu_labels_2_grade = {}
        for ITEMS_DICT in CUZU_LABELS:
            cuzu_label_1 = ITEMS_DICT['cuzu_label_1']
            cuzu_label_1_int_value = ITEMS_DICT['int_value']
            self._cuzu_labels_1_grade[cuzu_label_1] = cuzu_label_1_int_value
            ITEMS = ITEMS_DICT['items']
            for ITEM in ITEMS :
                cuzu_label_2 = ITEM['cuzu_label_2']
                cuzu_label_2_int_value = ITEM['int_value']
                self._cuzu_labels_2_grade[cuzu_label_2] = cuzu_label_2_int_value

    @property
    def cuzu_labels_1_grade(self):
        return self._cuzu_labels_1_grade

    @property
    def cuzu_labels_2_grade(self):
        return self._cuzu_labels_2_grade

cuzulabel2intvalue = CuZuLabel2IntValue()

def cuzu_label2int_label(_cuzu_tag, grade) :
    '''
    将 cuzu label 从文字转换为数字
    '''
    if grade==1:
        return cuzulabel2intvalue.cuzu_labels_1_grade[_cuzu_tag]
    elif grade==2:
        return cuzulabel2intvalue.cuzu_labels_2_grade[_cuzu_tag]
    return -1

def sentiment2intvalue(sentiment) -> int :
    if isinstance(sentiment, str) :
        try:
            sentiment = int(sentiment[-1])
            return sentiment
        except Exception as e:
            return 3
    else:
        return 3






